package com.imooc.ad.client.controller;

import com.alibaba.fastjson.JSON;
import com.imooc.ad.annotation.IgnoreResponseAdvice;
import com.imooc.ad.client.SponsorClient;
import com.imooc.ad.vo.AdPlan;
import com.imooc.ad.vo.AdPlanGetRequest;
import com.imooc.ad.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * Package: com.imooc.ad.client.controller
 * Description： OVER
 * Author: 范佳
 * Date: Created in 2019/3/6 21:45
 * Company: 公司
 * Copyright: Copyright (c) 2017
 * Version: 0.0.1
 * Modified By:
 */
@RestController
@Slf4j
public class SearchController {
    private final RestTemplate restTemplate;
    @Autowired
    private SponsorClient sponsorClient;

    @Autowired
    public SearchController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @SuppressWarnings("all")
    @IgnoreResponseAdvice
    @PostMapping("getAdPlansByRebbon")
    public CommonResponse<List<AdPlan>>  getAdPlansByRebbon(
            @RequestBody AdPlanGetRequest request
            ){
        log.info("ad-search getAdPlansByRebbon:{}", JSON.toJSONString(request));
//        return restTemplate.postForEntity(
//                "http://eureka-client-ad-sponsor/ad-sponsor/get/adPlan",request,CommonResponse.class
//        ).getBody();
        return sponsorClient.getAdPlans(request);

    }
}
